import { BaseEntity } from 'src/common/base.entity'
import { Item } from 'src/items/entities/item.entity'
import { Address } from 'src/users/entities/address.entity'
import { User } from 'src/users/entities/user.entity'
import { Entity, Column, ManyToOne } from 'typeorm'

export enum OrderStatus {
  PENDING = 'PENDING', // 下单未付款
  PAID = 'PAID', // 买家已付款
  SHIPPING = 'SHIPPING', // 卖家已发货
  DONE = 'DONE', // 交易完成
  REFUNDING = 'REFUNDING', // 退款中
  CLOSED = 'CLOSED' // 交易关闭
}

@Entity()
export class Order extends BaseEntity {
  @Column()
  itemPrice: number

  @Column()
  shippingFee: number

  @Column({
    type: 'enum',
    enum: OrderStatus,
    default: [OrderStatus.PENDING]
  })
  status: OrderStatus

  // TODO: 提交订单后禁止修改商品信息？或新增快照功能
  @ManyToOne(() => Item)
  item: Item

  @ManyToOne(() => User)
  seller: User

  @ManyToOne(() => User)
  user: User

  @ManyToOne(() => Address)
  address: Address
}
